﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using ArtheaEngine.Model;

namespace ArtheaEngine
{
    public static class UpdateManager
    {
        const int AreaTick=34*1000;
        static Timer areaUpdate = new Timer { Interval = AreaTick };
        static readonly HashSet<World> _worlds = new HashSet<World>();

        public static void AddWorld(World world) {
            _worlds.Add(world);
        }

        public static void RemoveWorld(World world) {
            _worlds.Remove(world);
        }

        static UpdateManager()
        {
            areaUpdate.Elapsed += UpdateAreas;
            areaUpdate.Enabled = true;
        }
    
        public static void UpdateAreas(object o, ElapsedEventArgs args) {
            foreach (var world in _worlds)
            {
                foreach (Area area in world.Areas)
                {
                    area.Update();
                }
            }
        }
    }
}
